<%--
  Created by IntelliJ IDEA.
  User: xdzy
  Date: 2017/4/15
  Time: 11:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <base href="<%=basePath%>">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>添加好友</title>
    <meta name="description" content="这是一个 index 页面">
    <meta name="keywords" content="index">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <meta name="apple-mobile-web-app-title" content="Amaze UI" />
    <link rel="stylesheet" href="./resources/css/amazeui.min.css"/>
    <link rel="stylesheet" href="./resources/css/admin.css">
    <link rel="stylesheet" href="./resources/css/style.css">
</head>
<body>
<jsp:include page="common1.jsp"/>
<div class="am-cf am-padding">
    <div class="am-fl am-cf">&nbsp;</div>
</div>
<div align="center"><strong class="am-text-primary am-text-lg">添加好友</strong></div>
<div class="am-u-sm-12 am-u-md-6 am-u-md-push-2">
    <form class="am-form am-form-horizontal">
        <div class="am-form-group">
            <label class="am-u-sm-3 am-form-label"></label>
            <div class="am-u-sm-9 " style="text-align: center">
                <strong id="resultMsg" style="color: red;"></strong>
            </div>
        </div>
        <div class="am-form-group">
            <label for="user-name" class="am-u-sm-3 am-form-label">对方账号</label>
            <div class="am-u-sm-9">
                <input type="text" id="user-name" placeholder="账号">
            </div>
        </div>

        <div class="am-form-group">
            <label for="doc-select-1" class="am-u-sm-3 am-form-label">选择分组</label>
            <div class="am-u-sm-9">
                <select id="doc-select-1">

                </select>
                <span class="am-form-caret"></span>
            </div>
        </div>
        <div class="am-form-group">
            <label for="user-intro" class="am-u-sm-3 am-form-label">申请信息</label>
            <div class="am-u-sm-9">
                <textarea class="" rows="5" id="user-intro" placeholder="">我是${sessionScope.loginUser.nickName},想要加你为好友</textarea>
                <small>50字以内</small>
            </div>
        </div>

        <div class="am-form-group">
            <div class="am-u-sm-9 am-u-sm-push-3">
                <button onclick="addFriend()" type="button" class="am-btn am-btn-primary am-btn-block">发送申请</button>
            </div>
        </div>
    </form>
</div>
<jsp:include page="common2.jsp"/>
<script>
    $.ajax({
        type:"post",
        url: "groupList.action",
        data:{
        },
        dataType:"json",//返回值类型
        success:function (data) {
            var jsonData=JSON.parse(data);
            for(var i=0;i<jsonData.length;i++){
                $("#doc-select-1").append("<option value='"+jsonData[i].gid+"'>"+jsonData[i].groupName+"</option>")
            }
        },
        error:function () {
            alert("系统异常")
        }
    });
    function addFriend() {
        $("#resultMsg").text("申请已提交，请耐心等待");
        $.ajax({
            type:"post",
            url: "./sendRequest.action",
            data:{
                "friendName":$("#user-name").val(),
                "group.gid":$("#doc-select-1").val(),
                "content":$("#user-intro").text()
            },
            dataType:"json",//返回值类型
            success:function (data) {
                $("#resultMsg").text(data);
            },
            error:function () {
                alert("系统异常")
            }
        });
    }
</script>
</body>
</html>
